package tr.edu.ozyegin.ccrg.wekaPerformanceRun.tests;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import tr.edu.ozyegin.ccrg.wekaPerformanceRun.WekaProcessRunCommand;

public class WekaProcessRunCommandTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {

	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testWekaProcessRunCommand() {

		WekaProcessRunCommand wekaProcessRunCommand = new WekaProcessRunCommand();
		assertNotNull(wekaProcessRunCommand);

	}

	@Test
	public void testExecuteStringStringString() {

		WekaProcessRunCommand wekaProcessRunCommand = new WekaProcessRunCommand();
		Process pTest = wekaProcessRunCommand.execute(
				"C:\\Development\\weka\\weka-3-7-3\\weka.jar",
				"weka.classifiers.trees.J48",
				"C:\\Development\\weka\\weka-3-7-3\\data\\weather.arff");

		String line;
		String consoleOutput = "";

		try {

			BufferedReader input = new BufferedReader(new InputStreamReader(
					pTest.getInputStream()));
			while ((line = input.readLine()) != null) {
				consoleOutput = consoleOutput + "\n" + line;

			}
			input.close();
		} catch (Exception err) {
			err.printStackTrace();
		}

		System.out.println(consoleOutput);

		assertNotNull(pTest);
	}

	@Test
	public void testExecute() {

		WekaProcessRunCommand wekaProcessRunCommand = new WekaProcessRunCommand();
		Process pTest = wekaProcessRunCommand.execute();

		String line;
		String consoleOutput = "";

		try {

			BufferedReader input = new BufferedReader(new InputStreamReader(
					pTest.getInputStream()));
			while ((line = input.readLine()) != null) {
				consoleOutput = consoleOutput + "\n" + line;

			}
			input.close();
		} catch (Exception err) {
			err.printStackTrace();
		}

		System.out.println(consoleOutput);
		
		assertNotNull(pTest);
	}

}
